#include<bits/stdc++.h>
#define ll long long
#define mid (l+r>>1)
#define OK Ll<=l&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<ll,ll>
#define ui unsigned ll
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int sum=0,f=0;
	char ch=gc();
	for(;!isdigit(ch);ch=gc())f|=(ch=='-');
	for(;isdigit(ch);ch=gc()) sum=((sum<<1)+(sum<<3)+(ch^48));
	return f?-sum:sum;
}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=1e7+5,M=1.1e6+5,inf=(1LL<<31)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,k,a[N],b[N],pw[N];
int q[N],h=1,t=1;
ll dp[N];
map<ll,int>P;
inline void Insert(ll w){
    P[w]++;
}
inline void Del(ll w){
    if(P[w]==1)P.erase(w);
    else P[w]--;
}
inline ll Min(){
    if(P.empty())return llf;
    return (*P.begin()).first;
}
inline void Main(){
	n=read(),k=read(),pw[0]=1;
	repn(i)a[i]=read(),pw[i]=mul(pw[i-1],23);
	int ans=0,sum=0;
	dp[0]=0,q[1]=0,a[0]=inf;
	repn(i){
        while(h<=t&&q[h]+k<i)Del(dp[q[h]]+a[q[h+1]]),h++;
        while(h<=t&&a[i]>=a[q[t]]){
            if(h!=t)Del(dp[q[t-1]]+a[q[t]]);
            t--;
        }
        q[++t]=i;
        if(h<t)Insert(dp[q[t-1]]+a[i]);
        dp[i]=min(Min(),dp[max(0,i-k)]+a[q[h]]);
        add(ans,mul(dp[i]%mod,pw[n-i]));
	}
	cout <<ans;
}
signed main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}	